#include <code_slice.hpp>
#include <iostream>

#include "catch2/catch.hpp"

TEST_CASE("test_code_slice", "[smart_ptr_cast]")
{
    {
        std::cout << "智能指针 父类 子类 转换" << std::endl;
        class BaseNode
        {
           public:
            BaseNode() {}
            virtual ~BaseNode() {}
        };
        class DeriveTreeNode : public BaseNode
        {
           public:
            DeriveTreeNode() {}
            ~DeriveTreeNode() {}
        };
        {

            std::cout << "智能指针 父类 ---> 子类  转换" << std::endl;
            std::shared_ptr<BaseNode> p1 = std::make_shared<DeriveTreeNode>();
            std::shared_ptr<DeriveTreeNode> p2 = std::dynamic_pointer_cast<DeriveTreeNode>(p1);

            std::cout << "智能指针 子类 ---> 父类  转换" << std::endl;
            std::shared_ptr<DeriveTreeNode> p3 = std::make_shared<DeriveTreeNode>();
            std::shared_ptr<BaseNode> p4 = std::dynamic_pointer_cast<BaseNode>(p3);
        }
        {

            std::cout << "智能指针 父类 ---> 子类  转换" << std::endl;
            std::unique_ptr<BaseNode> p1 = std::make_unique<BaseNode>();
            auto p2 = dynamic_unique_cast<DeriveTreeNode>(std::move(p1));
        }
    }
}